public class test2 {
    public String removeDuplicates(String s) {
        //利用栈
        Deque<Character> stack = new LinkedList<>();
        for(char ch:s.toCharArray()){
            if(stack.isEmpty()){
                stack.push(ch);
            }else{
                if(stack.peek()==ch){
                    stack.pop();
                }else{
                    stack.push(ch);
                }
            }
        }
        StringBuilder res = new StringBuilder();
        while(!stack.isEmpty()){
            res.append(stack.pop());
        }
        return res.reverse().toString();
    }
}
